package com.lalilu.homework3.fragment;

import android.app.Dialog;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.DialogFragment;

import java.util.Objects;

public class ChoiceDialogFragment extends DialogFragment {
    private final String[] genders = new String[]{"男", "女"};
    private NotifyDialogFragment listener;

    public void setListener(NotifyDialogFragment listener) {
        this.listener = listener;
    }

    @NonNull
    @Override
    public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
        return new AlertDialog.Builder(Objects.requireNonNull(getContext()))
                .setTitle("选择对话框")
                .setItems(genders, (dialog, which) -> this.listener.onDialogPositiveClicked(genders[which]))
                .create();
    }
}
